﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RooHui.OA.Biz;
using RooHui.Infrastructure.Entities.Entity;
using RooHui.Tool;

namespace RooHui.Admin.Web.Controllers
{
    public class PromotPolicyController : Controller
    {
        //
        // GET: /PromotionPolicy/
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 分页获取担保公司信息
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetPromotPolicyListByPage(int page, int pageSize)
        {
            int count = 0;
            var promotPolicyList = PromotPolicyBiz.GetPromotPolicyListByPage(page, pageSize, ref count);
            Dictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("Rows", promotPolicyList);
            dic.Add("Total", count);
            return Content(dic.ToJson());
        }

        public ActionResult PromotPolicyAdd()
        {
            return View();
        }

        /// <summary>
        /// 增加促销方案
        /// </summary>
        /// <param name="beginDate"></param>
        /// <param name="endDate"></param>
        /// <param name="enable"></param>
        /// <param name="activeCode"></param>
        /// <param name="attachPolicy"></param>
        /// <param name="createUser"></param>
        /// <param name="range"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult PromotPolicyAdd(DateTime beginDate, DateTime endDate, bool enable, int activeCode, String attachPolicy, int range)
        {
            bool bAddFlag = PromotPolicyBiz.PromotPolicyAdd(beginDate, endDate, enable, activeCode, attachPolicy, range);
            if (bAddFlag)
            {
                return Content("OK");
            }
            else
            {
                return Content("Failed");
            }
        }

        public ActionResult PromotPolicyEdit(int promotPolicyId, int editType)
        {
            ViewBag.promotPolicy = PromotPolicyBiz.GetPromotPolicyByID(promotPolicyId);
            ViewBag.edittype = editType;
            return View();
        }

        /// <summary>
        /// 修改促销方案
        /// </summary>
        /// <param name="promotPolicyId"></param>
        /// <param name="beginDate"></param>
        /// <param name="endDate"></param>
        /// <param name="enable"></param>
        /// <param name="activeCode"></param>
        /// <param name="attachPolicy"></param>
        /// <param name="createUser"></param>
        /// <param name="range"></param>
        /// <returns></returns>
        [HttpPost]
        [ValidateInput(false)]
        public ActionResult PromotPolicyEdit(int promotPolicyId, DateTime beginDate, DateTime endDate, bool enable, int activeCode, String attachPolicy, int range)
        {
            bool bModifyFlag = PromotPolicyBiz.PromotPolicyEdit(promotPolicyId, beginDate, endDate, enable, activeCode, attachPolicy, range);
            if (bModifyFlag)
            {
                return Content("OK");
            }
            else
            {
                return Content("Failed");
            }
        }

        /// <summary>
        /// 删除促销方案
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult PromotPolicyDelete(int id = 0)
        {
            bool bDelFlag = PromotPolicyBiz.PromotPolicyDelete(id);
            if (bDelFlag)
            {
                return Content("OK");
            }
            else
            {
                return Content("Failed");
            }
        }
    }
}
